package com.wzq.service.impl;

import com.wzq.annotation.WzqAutowired;
import com.wzq.annotation.WzqService;
import com.wzq.annotation.WzqTransactional;
import com.wzq.dao.AccountDao;
import com.wzq.dao.impl.JdbcAccountDaoImpl;
import com.wzq.pojo.Account;
import com.wzq.service.TransferService;

/**
 * @author wzq.Jolin
 * @company none
 * @create 2020-07-01 08:17
 */
@WzqService(value = "transferService")
@WzqTransactional
public class TransferServiceImpl  implements TransferService {

    @WzqAutowired
    private AccountDao accountDao ;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {


        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
//        int c = 1/0;
        accountDao.updateAccountByCardNo(from);
    }
}
